package ezCall;

public final class FindField_Text 
{
	
	private String   _FindField_Text;
    private int      _Find_Mode; 
	
    
    public final static int    FIND_MODE_NAME_COMPANY  = 0;
    public final static int    FIND_MODE_NOTE          = 1;
    public final static int    FIND_MODE_PHONE_NUMBER  = 2;
    public final static int    FIND_MODE_CATE          = 3;
    public final static int    FIND_MODE_NAME_FIRST    = 4;
    public final static int    FIND_MODE_COMPANY_FIRST = 5;
    public final static int    FIND_MODE_MAX           = 6;
    
    
    
    public final static char   FIND_MODE_CHAR_NAME_COMPANY  = '$';
    public final static char   FIND_MODE_CHAR_NOTE          = '*';
    public final static char   FIND_MODE_CHAR_PHONE_NUMBER  = '#';
    public final static char   FIND_MODE_CHAR_CATE          = '-';
    public final static char   FIND_MODE_CHAR_NAME_FIRST    = '+';
    public final static char   FIND_MODE_CHAR_COMPANY_FIRST = ';';

    private char[] _ModeArrayTable= { FIND_MODE_CHAR_NAME_COMPANY,
    		                          FIND_MODE_CHAR_NOTE,
    		                          FIND_MODE_CHAR_PHONE_NUMBER,
    		                          FIND_MODE_CHAR_CATE,
    		                          FIND_MODE_CHAR_NAME_FIRST,
    		                          FIND_MODE_CHAR_COMPANY_FIRST };
    		           
    
    
    private int _FieldCount;
    
    
    public FindField_Text()
    {
    	_FindField_Text = new String();
    	
    	_Find_Mode = FindField_Text.FIND_MODE_NAME_COMPANY;    
    	
    	_FieldCount = 0;
    }

    
    public void Set_Text( String TextStr )
    {
    	_FindField_Text = TextStr;
    	
    	_Find_Mode = Get_FindLastModeFromStr( TextStr );
    	
    	/*
    	for( int i=0; i<FIND_MODE_MAX; i++ )
    	{
    		if( _ModeArrayTable[i] == _FindField_Text.charAt(i) )
    		{
    			_Find_Mode = i;
    		}
    	}
    	*/
    }
    
    public String Get_Text()
    {
    	if( _Find_Mode == FIND_MODE_NAME_COMPANY ) return _FindField_Text;
    	else                                       return _FindField_Text.substring(1);    		
    }
    
    
    public final static int Get_FindLastModeFromStr( String Str )
    {
    	int Ret = FIND_MODE_NAME_COMPANY;

    	if( Str.length() == 0 ) return Ret;
    	
    	switch( Str.charAt(0) )
    	{
    	case FIND_MODE_CHAR_PHONE_NUMBER:
    		Ret = FIND_MODE_PHONE_NUMBER;
    		break;
    	case FIND_MODE_CHAR_NOTE:
    		Ret = FIND_MODE_NOTE;
    		break;
    	case FIND_MODE_CHAR_CATE:
    		Ret = FIND_MODE_CATE;
    		break;
    	case FIND_MODE_CHAR_NAME_FIRST:
    		Ret = FIND_MODE_CHAR_NAME_FIRST;
    		break;
    	case FIND_MODE_CHAR_COMPANY_FIRST:
    		Ret = FIND_MODE_CHAR_COMPANY_FIRST;
    		break;    		
    	}
    	
    	return Ret;
    }    
    
    public void Set_FindMode( int Mode )
    {
    	_Find_Mode = Mode;
    }    
    
    public int Get_FindMode()
    {
    	return _Find_Mode;
    }
    
    public void Change_FindModeFromString( String Str )
    {
    	_Find_Mode =  FindField_Text.Get_FindLastModeFromStr(Str);
    }       
    
    public int Get_StrSize()
    {
    	return _FindField_Text.length();
    }
    
    public boolean isValidText()
    {
    	if( _FindField_Text.length() == 0 ) return false;
    	
    	if( _FindField_Text.length() == 1  && _Find_Mode != FIND_MODE_NAME_COMPANY ) return false;
    	    	
    	return true;
    }
}
